package com.atguigu.srb.core.service.impl;

import com.atguigu.srb.common.utils.PageUtils;
import com.atguigu.srb.common.utils.Query;
import com.atguigu.srb.core.entity.IntegralGrade;
import com.atguigu.srb.core.mapper.IntegralGradeMapper;
import com.atguigu.srb.core.service.IntegralGradeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * <p>
 * 积分等级表 服务实现类
 * </p>
 *
 * @author cfx
 * @since 2022-06-25
 */
@Service
public class IntegralGradeServiceImpl extends ServiceImpl<IntegralGradeMapper, IntegralGrade> implements IntegralGradeService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        //1.获取key
        String key = (String) params.get("key");
        QueryWrapper<IntegralGrade> wrapper = new QueryWrapper<>();
        if (StringUtils.hasText(key)) {
            wrapper.eq("integral_start", key).or().eq("integral_end", key).or().eq("borrow_amount", key);
        }
        IPage<IntegralGrade> page = this.page(
                new Query<IntegralGrade>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }
}
